package com.dyna.digit.process.controller;

import com.dyna.digit.process.domain.entity.DigitProject;
import com.dyna.digit.process.domain.entity.DigitUnitInfo;
import com.dyna.digit.process.domain.query.DigitProjQuery;
import com.dyna.digit.process.domain.resp.DigitOverProjResp;
import com.dyna.digit.process.domain.resp.DigitProjectPage;
import com.dyna.digit.process.service.DigitProjectService;
import com.dyna.domain.resp.PageResult;
import com.dyna.domain.resp.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhoucaiwang
 * @date 2023/11/11
 */

@Api(value = "项目列表", tags = {"项目申报"})
@RestController
@RequestMapping("/proj")
public class DigitProjectController {

    private final DigitProjectService digitProjectService;

    @Autowired
    public DigitProjectController(DigitProjectService digitProjectService) {
        this.digitProjectService = digitProjectService;
    }

    @ApiOperation(value = "获取项目列表", notes = "获取项目列表")
    @PostMapping("/getPageList")
    public R<PageResult<DigitProjectPage>> getPageList(@RequestBody DigitProjQuery digitProjQuery) {
        digitProjQuery.setPageNum((digitProjQuery.getPageNum() - 1) * digitProjQuery.getPageSize());
        PageResult<DigitProjectPage> queryPage = digitProjectService.getPageList(digitProjQuery);
        return R.data(queryPage);
    }

    @ApiOperation(value = "单位列表")
    @GetMapping("/getUnitListByType")
    public R<List<DigitUnitInfo>> getUnitListByType(@RequestParam("type") String type) {
        return R.data(digitProjectService.getUnitListByType(type));
    }

    @ApiOperation(value = "关联历年项目")
    @GetMapping("/getOverProjList")
    public R<List<DigitOverProjResp>> getOverProjList() {
        return R.data(digitProjectService.getOverProjList());
    }

    @ApiOperation(value = "连表查询MySQL8并发量")
    @PostMapping("/testDigitPageQPS")
    public R<List<DigitProjectPage>> testDigitPageQPS(@RequestBody DigitProjQuery digitProjQuery) {
        return R.data(digitProjectService.testDigitPageQPS(digitProjQuery));
    }

    @ApiOperation(value = "测试连表查询countMySQL8并发量")
    @PostMapping("/testDigitCountQPS")
    public R<Long> testDigitCountQPS(@RequestBody DigitProjQuery digitProjQuery) {
        return R.data(digitProjectService.testDigitCountQPS(digitProjQuery));
    }

    @ApiOperation(value = "详情")
    @GetMapping("/detail/{id}")
    public R<DigitProject> detail(@PathVariable Integer id) {
        return R.data(digitProjectService.detail(id));
    }

}
